
import random
#from jdbcdao.impl.sqliteconnection import SqliteConnection
from jdbcdao.impl.mysqlconnection import MysqlConnection
from jdbcdao.jdbctemplate import JdbcTemplate
from user.model.userwapper import UserWapper


def creat_table():
    dao.ddl('''CREATE TABLE user
            (ID INT PRIMARY KEY     NOT NULL,
            NAME           TEXT    NOT NULL,
            ADDR            TEXT     NOT NULL
            )''')
    print('crete table success.')


def insert_user():
    id = random.randint(1,99)
    dao.dml("insert into user(id,name,addr) values (%d,'qiao__%d','北京_%d')" % (id,id,id))


def get_all_users():
    sql = 'select id,name,addr from user'
    users = dao.dql(sql, UserWapper())
    for u in users:
        print(u)


'''测试'''

#dao = JdbcTemplate(SqliteConnection('database.db'))
dao = JdbcTemplate(MysqlConnection('root','root','test'))
#creat_table()
#insert_user()
get_all_users()